package pers.cz.postgirl.core.db.simpledb;

import com.alibaba.druid.pool.DruidDataSource;
import pers.cz.jefconfig.config.JefConfiguration;
import pers.cz.postgirl.core.enums.DbConfigItem;


import javax.sql.DataSource;

/**
 * @program: JefLogTail
 * @description: 数据源配置
 * @author: Cheng Zhi
 * @create: 2023-03-05 13:29
 **/
public class DataSourceFactory {

    private volatile static DataSource dataSource;

    private DataSourceFactory() {

    }

    public static DataSource getDbDataSource() {

        if (dataSource == null) {
            synchronized (DataSourceFactory.class) {
                if (dataSource == null) {
                    dataSource = new DataSourceFactory().getDataSource();
                }
            }
        }

        return dataSource;
    }
    public DataSource getDataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUrl(JefConfiguration.get(DbConfigItem.DB_URL));
        dataSource.setUsername(JefConfiguration.get(DbConfigItem.DB_USERNAME));
        dataSource.setPassword(JefConfiguration.get(DbConfigItem.DB_PASSWORD));
        dataSource.setDriverClassName(JefConfiguration.get(DbConfigItem.DB_DRIVER));
        dataSource.setMaxActive(10);

        return dataSource;
    }


}
